
require 'eycap/recipes'
# =============================================================================
# ENGINE YARD EXPRESS REQUIRED VARIABLES
# =============================================================================

# =============================================================================
# CHANGE THESE
# =============================================================================

# Once you have the IP of your Express image, put it in here
set :express_ip, "172.16.216.129"
# If you don't have ssh keys set up, then put your express user's password here
set :password, "vador5"
 


set :application, "My Blog"
set :repository,  "set your repository location here"

# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
set :deploy_to, "/var/www/#{application}"

# If you aren't using Subversion to manage your source code, specify
# your SCM below:
# set :scm, :subversion

#role :app, "your app-server here"
#role :web, "your web-server here"
#role :db,  "your db-server here", :primary => true

# :primary => true. 
task :express do
  role :web, "#{express_ip}"
  role :app, "#{express_ip}", :merb => true
  role :db, "#{express_ip}", :primary => true
  set :merb_env, "express"
  set :environment_database, Proc.new { express_database }
end





set :sql_pass,         '77zxcvb77'
set :application,      'merb'
set :keep_releases,    5
set :monit_group,      'merb'
set :deploy_to,        '/data/merb'
set :runner,           'express'
set :express_database, 'merb_prod'
set :sql_user,         'express_db'
set :sql_host,         'localhost'

default_run_options[:pty] = true


namespace(:mongrel) do
  task :restart, :roles => :app do
      run "sudo monit restart all -g merb"
  end
	  
  task :start, :roles => :app do
      run "sudo monit start all -g merb"
  end
		    
  task :stop, :roles => :app do
      run "sudo monit stop all -g merb"
  end
			      
  task :kill, :roles => :app, :on_error => :continue do
      run "sudo pkill -9 mongrel_merb"
  end
end

namespace(:deploy) do  
  task :symlink_configs, :roles => :app, :except => { :no_symlink => true } do
    run <<-CMD
    cd #{release_path} &&
    ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml &&
    ln -nfs #{shared_path}/config/mongrel_cluster.yml #{release_path}/config/mongrel_cluster.yml
    CMD
  end
								      
  desc "Long deploy will throw up the maintenance.html page and run migrations 
        then it restarts and enables the site again."
  task :long do
    transaction do
      update_code
      web.disable
      symlink
      migrate
    end
   
    restart
    web.enable
  end

  desc "Restart the Mongrel processes on the app server by calling restart_mongrel_cluster."
  task :restart, :roles => :app do
    mongrel.restart
  end
  desc "Start the Mongrel processes on the app server by calling start_mongrel_cluster."
  task :spinner, :roles => :app do
    mongrel.start
  end
  task :migrate, :roles => :app, :except => { :no_symlink => true } do
    run "cd #{current_path} && MERB_ENV=#{merb_env} rake db:migrate"
  end
end




# TASKS
# Don't change unless you know what you are doing!
after "deploy", "deploy:cleanup"
after "deploy:migrations", "deploy:cleanup"
after "deploy:update_code","deploy:symlink_configs"
# uncomment the following to have a database backup done before every migration
# before "deploy:migrate", "db:dump"



